package com.liwei.baselib.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

/**
 * Created by liwei on 2017/3/15.
 */

public class ToolIntent {
    private static Intent intent = null;
    public static final String DATA = "data";

    /**
     * 跳转到Activity
     *
     * @param context 上下文
     * @param aClass
     */
    public static void ClassToActivity(Context context, Class aClass) {
        intent = new Intent();
        intent.setClass(context, aClass);
        context.startActivity(intent);
    }

    /**
     * 跳转到相对应的Activiyy 此Activity 需要单例 的
     *
     * @param context 上下文
     * @param aClass
     */
    public static void ClassToLogin(Context context, Class aClass, int flage) {
        intent = new Intent();
        intent.setClass(context, aClass);
        intent.addFlags(flage);
        context.startActivity(intent);
    }

    /**
     * 带参数的跳转
     *
     * @param context
     * @param aClass
     * @param mBundle bundle 带的参数
     */
    public static void ClassToActivity(Context context, Class aClass, Bundle mBundle) {
        intent = new Intent();
        intent.setClass(context, aClass);
        intent.putExtras(mBundle);
        context.startActivity(intent);
    }


    /**
     * @param context
     * @param aClass
     * @param mdate   String 类型的参数
     */
    public static void ClassToActivity(Context context, Class aClass, String mdate) {
        intent = new Intent();
        intent.setClass(context, aClass);
        intent.putExtra(DATA, mdate);
        context.startActivity(intent);
    }

    /**
     * 多参数跳转
     *
     * @param context
     * @param aClass
     * @param mdate
     * @param bundle
     */
    public static void ClassToActivity(Context context, Class aClass, String mdate, Bundle bundle) {
        intent = new Intent();
        intent.setClass(context, aClass);
        intent.putExtra(DATA, mdate);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }


    /**
     * 返回结果的跳转Activity
     *
     * @param context
     * @param aClass
     * @param code
     */
    public static void ClassToActivityResult(Context context, Class aClass, int code) {
        intent = new Intent();
        intent.setClass(context, aClass);
        ((Activity) context).startActivityForResult(intent, code);
    }

    /**
     * 返回结果的跳转Activity 并且带入参
     *
     * @param context
     * @param aClass
     * @param code
     */
    public static void ClassToActivityResult(Context context, Class aClass, Bundle mBundle, int code) {
        intent = new Intent();
        intent.putExtras(mBundle);
        intent.setClass(context, aClass);
        ((Activity) context).startActivityForResult(intent, code);
    }

    /**
     * int类型的数值传入
     *
     * @param context
     * @param aClass
     */
    public static void ClassToActivity(Context context, Class aClass, int mdate) {
        intent = new Intent();
        intent.setClass(context, aClass);
        intent.putExtra(DATA, mdate);
        context.startActivity(intent);
    }

    /**
     * 关闭Activity 开启一个新 的Activity 在一个新的栈中
     *
     * @param context
     * @param aClass
     */
    public static void ClearOldActivity(Context context, Class aClass) {
        intent = new Intent();
        intent.setClass(context, aClass);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(intent);
    }


}